package com.zc.service_sms.controller;

import com.zc.commonutils.Result;
import com.zc.service_sms.service.SmsService;
import com.zc.service_sms.utils.RandomUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.validation.constraints.NotBlank;
import javax.validation.constraints.Pattern;


@RestController
@RequestMapping("/zcmsm/msm")
@Validated
public class SmsController {

    @Autowired
    private SmsService smsService;

    @GetMapping("/send/{phone}")
    public Result sendMsm(
            @Pattern(regexp = "^1([38][0-9]|4[579]|5[0-3,5-9]|6[6]|7[0135678]|9[89])\\d{8}$",message = "手机号格式不对")
            @NotBlank
            @PathVariable String phone) throws Exception {
       boolean isSend= smsService.send(phone);
       if (isSend){
           return Result.ok().message("发送成功");
       }else {
           return Result.error().message("请稍后再试");
       }
    }
}
